package com.diapoclic.servlet;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ConnexionServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)						
											throws IOException, ServletException{
		
		String name = (String)request.getParameter("name");
		String password = (String)request.getParameter("password");
		HttpSession session = request.getSession();
		session.setAttribute("name", name);
		session.setAttribute("password", password);
		
		
		//La gestion du cookie: enregistre les donn�es du formulaire dans des cookies si le chckbox est coch�
		if(request.getParameter("auto_connect") != null){
			System.out.println("Cr�ation des cookies.");
			Cookie nameCookie = new Cookie("name", name);
			Cookie passwordCookie = new Cookie("password", password);
			response.addCookie(nameCookie);
			response.addCookie(passwordCookie);
		}
		
//		if(name == "register" || password == "register"){
//			request.getRequestDispatcher("register.jsp").forward(request,response);
//		}
//		
//		else {
		request.getRequestDispatcher("profile.jsp").forward(request, response);
//		}
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)						
											throws IOException, ServletException{
		doGet(request, response);
	}	
}

